﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html ng-app="CCFlowAdmin"  xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>本机表的创建</title>
    
    <!--<script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jsTree.ddl.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jstree.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/commonYangYH.js"></script>-->

    <!--<link href="../Style/Table0.css" rel="stylesheet" type="text/css" />-->

    <link href="../../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />

    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>

    <script src="../../../Scripts/angularjs/angular.js"></script>
    <script src="../../../Scripts/angularjs/angular.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-aria.js"></script>
    <script src="../../../Scripts/angularjs/angular-aria.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-animate.js"></script>
    <script src="../../../Scripts/angularjs/angular-animate.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-cookies.js"></script>
    <script src="../../../Scripts/angularjs/angular-cookies.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-loader.js"></script>
    <script src="../../../Scripts/angularjs/angular-loader.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-message-format.js"></script>
    <script src="../../../Scripts/angularjs/angular-message-format.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-messages.js"></script>
    <script src="../../../Scripts/angularjs/angular-messages.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-mocks.js"></script>
    <script src="../../../Scripts/angularjs/angular-resource.js"></script>
    <script src="../../../Scripts/angularjs/angular-resource.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-route.js"></script>
    <script src="../../../Scripts/angularjs/angular-route.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-sanitize.js"></script>
    <script src="../../../Scripts/angularjs/angular-sanitize.min.js"></script>
    <script src="../../../Scripts/angularjs/angular-scenario.js"></script>
    <script src="../../../Scripts/angularjs/angular-touch.js"></script>
    <script src="../../../Scripts/angularjs/angular-touch.min.js"></script>
    <script src="../../../Scripts/app.js"></script>

    <base target="_self" />
    <!--<script type="text/javascript">
        function Esc() {
            if (event.keyCode == 27)
                window.close();
            return true;
        }

        function Save() {
            alert('开始执行保存');
        }

        function SaveAndClose() {
            Save();
            window.close();
        }

        function Close() {
            window.close();
        }

       $(function () {
            InitPage();
        });

        function InitPage() {
            var sf_Table = GetQueryString("FK_SFTable");

            $.ajax({
                type: 'post',
                async: true,
                url: "SFTableHandler.ashx?DoType=CreateTableDataInit&FK_SFTable=" + sf_Table + '&m=' + Math.random(),
                dataType: 'html',
                success: function (data) {

                    console.log(data);
                    data = JSON.parse(data);
                     
                    //给公共属性赋值.
                    $("#TB_Width").val(data.W);
                    $("#TB_Height").val(data.H);
                    $("#TB_Title").val(data.Title);

                    //设置返回值模式.
                    $("#RB_PopValFormat_" + data.PopValFormat ).attr('checked', 'checked');
                }
            });
        }
     
    </script>-->
</head>

<body class="easyui-layout">
    <div ng-controller="CCFlow_SFConfCreationController" ng-init="onInit()">

        <table>
            <tr>
                <th>顺序号</th>
                <th>编号</th>
                <th>名称</th>
                <th>父级</th>
                <th>操作</th>
            </tr>

            <tr ng-repeat="conf in confs">
                <td>{{$index}} </td>
                <td class="style3">
                    <input ng-model="conf.id" class="easyui-textbox" maxlength="20" onkeyup="purgeValue(valuePolicy.Int, this)" onmouseout="purgeValue(valuePolicy.Int, this)" />
                </td>
                <td class="style2">
                    <input ng-model="conf.value" class="easyui-textbox" maxlength="20" />
                </td>
                <td>
                    <select ng-model="conf.parent">
                        <option ng-repeat="config in confs" value="config.id">{{config.value}}</option>
                    </select>
                </td>
                <td class="style1">
                    <a href="#" ng-click="removeConf($index)"><span></span>删除</a>
                </td>
            </tr>
        </table>

        <input type=button value="添加" class="easyui-button" ng-click="addConf()" />
        <input type=button value="保存" class="easyui-button" ng-click="doSubmit(false)" />
        <input type=button value="保存并关闭" class="easyui-button" ng-click="doSubmit(true)" />
        <input type=button value="关闭" class="easyui-button" onclick="window.close();" />
    </div>

    <script type="text/javascript">
        function createGuid() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        }

        var valuePolicy = {
            AlphaNum: "alpha_num",
            Int: "int",
            Decimal: "decimal",
            DateTime: "datetime",
            Password: "password",
            DBCCase: "dbc_case"
        };

        function purgeValue(policy, source) {
            switch (policy) {
                case valuePolicy.AlphaNum:
                    {
                        source.value = source.value.replace(/[^a-zA-Z0-9_\-\.]/g, '');
                        break;
                    }
                case valuePolicy.Int:
                    {
                        source.value = source.value.replace(/[^\d]/g, '');
                        break;
                    }
                case valuePolicy.Decimal:
                    {
                        source.value = source.value.replace(/[^0-9\.]/g, '');
                        break;
                    }
                case valuePolicy.Password:
                    {
                        break;
                    }
                case valuePolicy.DBCCase:
                    {
                        source.value = source.value.replace(/[\uFF00-\uFFFF]/g, '');
                        source.value = source.value.replace(/[\u4E00-\u9FA5]/g, '');
                        break;
                    }
                default:
                    {
                        source.value = source.value.replace(/[\uFF00-\uFFFF]/g, '');
                        source.value = source.value.replace(/[\u4E00-\u9FA5]/g, '');
                        break;
                    }
            }
        }

        function setItemID(items) {
            for (var i = 0; i < items.length; i++) {

                items[i].id = (i + 1).toString();
            }
        }

        var appModule = angular.module("CCFlowAdmin", []);

        appModule.controller("CCFlow_SFConfCreationController",

        function ($scope, $location, $http) {

            $scope.confs = [{ id: "1", value: "", parent: "" }, { id: "2", value: "", parent: "1" }];

            var sf_Table = GetQueryString("FK_SFTable");

            $scope.addConf = function ()
            {
                var id = "1"; //Math.random().toString(); //createGuid();

                if ($scope.confs.length > 0)
                {
                   id = (Number($scope.confs[$scope.confs.length - 1].id) + 1).toString();
                }

                $scope.confs.push({ id: id, value: (sf_Table + "-Item-"+ id) });

                //setItemID($scope.confs);
            };

            $scope.removeConf = function (index) {
                $scope.confs.splice(index, 1);

                //setItemID($scope.confs);
            };

            //$scope.shouldShowAddButton = function () {
            //    return ($scope.confs.length < 100);
            //};

            //$scope.shouldShowRemoveButton = function () {
            //    return (($scope.confs.length >= 1) && ($scope.confs.length <= 100));
            //};

            $scope.onInit = function () {
                //var sf_Table = GetQueryString("FK_SFTable");

                var protocol = $location.protocol();
                var host = $location.host();
                var port = $location.port();

                var url = protocol + "://" + host + ":" + port + "/WF/Admin/CCFormDesigner/SFTable/";

                var servicePoint = "SFTableHandler.ashx?DoType=CreateTableDataInit&FK_SFTable=" + sf_Table + '&m=' + Math.random();

                alert(url + servicePoint);

                $http.get(url + servicePoint).success(function (data, status, headers, config) {
                    $scope.confs = [];

                    //for (var key in data) {
                    //    $scope.confs.push({ id: key, value: data[key] });
                    //}

                    for (i = 0; i < data.length; i++) {
                        $scope.confs.push({ id: data[i].id, value: data[i].value });
                    }

                }).error(function (data, status, headers, config) {
                    //for (var key in data) {
                    //    alert(key + ": " + data[key]);
                    //}

                    alert("Error!");
                });
            };

            $scope.doSubmit = function (shouldCloseWindow) {
                //var sf_Table = GetQueryString("FK_SFTable");

                var protocol = $location.protocol();
                var host = $location.host();
                var port = $location.port();

                var url = protocol + "://" + host + ":" + port + "/WF/Admin/CCFormDesigner/SFTable/";

                var servicePoint = "SFTableHandler.ashx?DoType=CreateTableDataSave&FK_SFTable=" + sf_Table + '&m=' + Math.random();

                $http.post(url + servicePoint, $scope.confs).success(function (data, status, headers, config) {
                    var result = data;

                    alert("保存成功！");

                    if (shouldCloseWindow == true) {
                        window.close();
                    }
                    
                    //window.location = url + "/";

                }).error(function (data, status, headers, config) {
                    //for (var key in data) {
                    //    alert(key + ": " + data[key]);
                    //}

                    alert("Error!");
                });
            };
        });
    </script>
</body>
</html>
